
<?php 
function actual_date ($anio, $mes, $dia)  
            {   
                $week_day_now = date("w", mktime(0,0,0,$mes,$dia,$anio));
                $week_days = array ("Domingo", "Lunes", "Martes", "Miercoles", "Jueves", "Viernes", "Sabado");  
                $months = array ("", "Enero", "Febrero", "Marzo", "Abril", "Mayo", "Junio", "Julio", "Agosto", "Septiembre", "Octubre", "Noviembre", "Diciembre");  

                $year_now = $anio;  
                $month_now = intval($mes);  
                $day_now = $dia;  
                $date = $week_days[$week_day_now] . ", " . $day_now . " de " . $months[$month_now] . " de " . $year_now;   
                return $date;    
            }  
            
?>
  <table border="0" cellpanding="0" cellspacing="0" class=" tableReport " >
  <tr>
        <td class="titleReport" colspan="7">
            <form  action="<?php echo url_for('dashboard/rentAlim') ?>" method="post">
            <label for="from">Desde</label>
            <input type="text" id="from" name="from" value="<?php echo $from ?>">
            <label for="to">hasta</label>
            <input type="text" id="to" name="to" value="<?php echo $to ?>">
            <input type="submit" id="enviar" value="enviar">
            </form>
        </td>
    </tr>
    
    <tr>
        <td class="totalReport" style="background: #fff; font-size: 11px;" colspan="7">
            <?php if($from){?>
            <label for="from">Desde</label> [ 
            <?php $from = explode("-",$from);
            echo actual_date($from[0],$from[1], $from[2])."] "; }?>
            <?php if($to){?>
            <label for="to" style="padding-left: 20px;">hasta</label> [ 
            <?php $to = explode("-",$to);
            echo actual_date($to[0],$to[1], $to[2])."] ";} ?>
        </td>
    </tr>
    <tr>
        <td colspan="7">
            
        
<table id="tablesorter-demo" border="0" cellpanding="0" cellspacing="0" class="tablesorter">
    
  
    
    <thead>
    <tr>
        <th class="titleReport" width="80px">Fecha</th>
        <th class="titleReport" width="100px">Cliente</th>
        <th class="titleReport" width="70px">Cantidad</th>
        <th class="titleReport" width="400px">Bulto</th>
        <th class="titleReport" width="70px">Precio Unin</th>
        
        <th class="titleReport" width="70px">Precio</th>
        <th class="titleReport" width="70px">Costo</th>
    </tr>
    </thead>
    <tbody>
    <?php 
    $totalCantidad     = 0;
    $totalVenta     = 0;
    
    
    foreach ($camionetas as $camioneta){
        
        if(count($camioneta->getServicio())>=1){
        foreach ($camioneta->getServicio() as $servicio){
            if($servicio->getProducto()){
        ?>
    <tr>
        <td class="lineaReport" align="center">
        <?php $fecha = explode(" ",$camioneta->getFechaAsig());
              echo $fecha[0];
        ?></td>
        <td class="lineaReport" align="center"><?php 
        echo "DF".$camioneta->getUsuarioId(); ?></td>
        <td class="lineaReport" align="center"><?php 
        echo $servicio->getCantidad();
        $totalCantidad = $totalCantidad + $servicio->getCantidad();
        ?></td>
        <td class="lineaReport" align="right"><?php 
        if($servicio->getProducto())
        echo $servicio->getProducto()." ";
        
        
        foreach ($servicio->getProducto()->getProductoPrecio() as $presentacion){
            if($presentacion->getId()==$servicio->getPresentacionId()){
            echo $presentacion->getPresentacion(); 
            $precio_unitario = $presentacion->getPrecio();
            }
            
        }
        ?></td>
        <td class="lineaReport" align="right"><?php 
        echo number_format($servicio->getPrecio()/$servicio->getCantidad(),2,',','');
        ?></td>
        
        <td class="lineaReport" align="right"><?php 
        echo number_format($servicio->getPrecio()+0,2,',','');
        
        $totalVenta = $totalVenta + $servicio->getPrecio();
        ?></td>
        <td class="lineaReport" align="right">
        0,00
        </td>
    </tr>
    
    <?php
        }}}
    
        }?>
    
    
 
    
    
    </tbody>
</table>
            
            </td></tr>
    
         <?php if(count($camionetas)>0){
    ?>
    <tr>
        <th class="titleReport" width="80px">Total</th>
        <th class="titleReport" width="100px"></th>
        <td class="totalReport" width="70px" align="center"><?php echo number_format($totalCantidad,0,',','.');?></td>
        <th class="titleReport" width="400px"></th>
        <th class="titleReport" width="70px"></th>
        
        <td class="totalReport" width="70px" align="right"><?php echo number_format($totalVenta,2,',','.');?></td>
        <th class="titleReport" width="70px"></th>
    </tr>
    <?php } ?>

  </table>
  
  
  <script type="text/javascript">
	$(function() {		
		$("#tablesorter-demo").tablesorter({sortList:[[0,0],[2,1]], widgets: ['zebra']});
		$("#options").tablesorter({sortList: [[0,0]], headers: { 3:{sorter: false}, 4:{sorter: false}}});
	});	
	
  $(function() {
    $( "#from" ).datepicker({
      defaultDate: "+1w",
      dateFormat: "yy-mm-dd",
      changeMonth: true,
      numberOfMonths: 3,
      onClose: function( selectedDate ) {
        $( "#to" ).datepicker( "option", "minDate", selectedDate );
      }
    });
    $( "#to" ).datepicker({
      defaultDate: "+1w",
      dateFormat: "yy-mm-dd",
      changeMonth: true,
      numberOfMonths: 3,
      onClose: function( selectedDate ) {
        $( "#from" ).datepicker( "option", "maxDate", selectedDate );
      }
    });
  });
  
  
  </script>
  